<?php

	class CacheQuery {

		const EXPIRE = 86400;

		public static function fetchall($name, $sql, $expire = self::EXPIRE) {

			$cache = AppCache::getInstance();
			if (!$result = $cache->get($name)) {
				$db = Database::getInstance();

				$result = $db->fetch_query($sql);
				$cache->set($name, $result, $expire);
			}

			return $result;
		}

		public static function one($name, $sql, $expire = self::EXPIRE) {
			$cache = AppCache::getInstance();
			if (!$result = $cache->get($name)) {
				$db     = Database::getInstance();
				$result = $db->one($sql);
				$cache->set($name, $result, $expire);
			}

			return $result;
		}

		public static function flushCache($name) {
			AppCache::getInstance()->del($name);
		}

	}